import React, { FC } from 'react';
import { Button } from 'antd';
import { RegistePlanModal } from './RegistePlanModal';
import { Plane } from '../../../types/plane.type';

type Props = {
    onOk: () => void;
    setOpen: (open: boolean) => void;
    open: boolean;
    selectedPlane?: Plane;
    setSelectedPlane: (p?: Plane) => void;
}

export const PlaneForm: FC<Props> = ({ onOk, setOpen, open, selectedPlane, setSelectedPlane }) => {
    const showModal = () => {
        setSelectedPlane(undefined);
        setOpen(true);
    };
    const handleCancel = () => {
        setOpen(false);
    };
    const handleOnOk = () => {
        onOk?.();
    }
    return <>
        <Button type='primary' onClick={showModal}>Register</Button>
        {open && <RegistePlanModal show={open} onOk={handleOnOk} onCancel={handleCancel} selectedPlane={selectedPlane} />}
    </>
}